find_program(mktemp NAMES mktemp)

if(mktemp)
  execute_process(COMMAND mktemp -d OUTPUT_VARIABLE bindir OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
  string(RANDOM LENGTH 12 _s)
  if(DEFINED ENV{TEMP})
    set(bindir $ENV{TEMP}/${_s})
  elseif(IS_DIRECTORY "/tmp")
    set(bindir /tmp/${_s})
  else()
    set(bindir ${CMAKE_CURRENT_BINARY_DIR}/${_s})
  endif()
endif()
